/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.auth.business;

import java.util.List;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import reportcenter.auth.dominio.Roles;
import reportcenter.support.dbutil.JPAFactory;
import reportcenter.datasource.dominio.DataSource;

/**
 *
 * @author renan_luz
 */
public class RolesDao {

    public List<Roles> getAll() {
        EntityTransaction tx = JPAFactory.getInstance().getManager().getTransaction();
        tx.begin();

        List<Roles> roles = null;
        try {
            Query query = JPAFactory.getInstance().getManager().createNamedQuery("Roles.findAll");
            roles = query.getResultList();

            tx.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            tx.rollback();
        }
        return roles;
    }

    public void add(Roles role) {
        EntityTransaction tx = JPAFactory.getInstance().getManager().getTransaction();
        tx.begin();
        try {
            JPAFactory.getInstance().getManager().persist(role);
            tx.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            tx.rollback();
        }
    }


    public void delete(Roles role) {
        EntityTransaction tx = JPAFactory.getInstance().getManager().getTransaction();
        tx.begin();
        try {

            JPAFactory.getInstance().getManager().remove(role);

            tx.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
            tx.rollback();
        }
    }
}
